<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class DynamicInforMation extends Model
{
    use HasFactory;
    use SoftDeletes;

    protected $table = 'dynamic_information';

    protected $guarded = [];

    public function getDynamicImgsAttribute($value)
    {
        return explode(',',$value);
    }

    public function getIssueTimeAttribute($value)
    {
        return [date('m',strtotime($value)).'月',date('m-d',strtotime($value))];
    }

    public function intermediaryUser()
    {
        return $this->belongsTo(IntermediaryUser::class,'intermediary_id');
    }

    public static function addDynamic($data)
    {
        return self::create($data,true);
    }

    public static function getDynamicData($user_id)
    {
        return self::with('intermediaryUser')->where('intermediary_id',$user_id)->orderBy('issue_time','desc')->get();
    }

    public static function deleteData($dynamic_id)
    {
        return self::destroy($dynamic_id);
    }
}
